package CrowdCounting.Model.CrowdCounting;

import Const.State;
import CrowdCounting.Model.DisplayFrame;
import CrowdCounting.Model.Util;

import javax.swing.*;
import java.io.File;

public class CrowdCountingDisplayFrame extends DisplayFrame {

    public CrowdCountingDisplayFrame(String name, int width, int height) {
        setTitle(name);
        setSize(width, height);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }


    public File readImage(String imagePath) throws InterruptedException {
        int count = 0;
        File imageFile = new File(imagePath);
        while(!Util.fileExistenceCheck(imageFile) || !Util.checkImage(imageFile)){
            count++;
            if (count == 100 || CrowdCountingShow.getShowLabelThreadState() == State.CLOSE) return null;
            Thread.sleep(600);
            imageFile = new File(imagePath);
            System.out.println(imagePath+ " 等待加载中...");
        }
        System.out.println(imagePath + "加载成功");
        return imageFile;
    }
}

